import Vue from 'vue'
import cookies from 'vue-cookies'

import appcfg from '@/app.config'

Vue.use(cookies)

function getTokenKey() {
  return appcfg.token.key
}

function getToken() {
  return cookies.get(getTokenKey())
}

function setToken(token) {
  if (!token) {
    console.warn('Remove token!')
    return cookies.remove(getTokenKey())
  }
  return cookies.set(getTokenKey(), token)
}

const cookieKeys = () => {
  return cookies.keys()
}

export default {
  setToken,
  getToken,
  cookieKeys
}

